package logic

import (
	"MyBlogv2/blog-common/helper"
	"MyBlogv2/blog-common/models"
	"context"
	"github.com/jinzhu/copier"

	"MyBlogv2/Servers/Article/article"
	"MyBlogv2/Servers/Article/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetTimeLineListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetTimeLineListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTimeLineListLogic {
	return &GetTimeLineListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetTimeLineListLogic) GetTimeLineList(in *Article.ArticleRequest) (*Article.TimeLineVoList, error) {
	var articleVo []models.ArticleVo
	var articleTimeLineVo []*Article.TimeLineVo
	models.Db.Model(new(models.ArticleVo)).Find(&articleVo)
	copier.Copy(&articleTimeLineVo, &articleVo)
	for i, v := range articleVo {
		articleTimeLineVo[i].CreateTime = helper.MyTimeToTimestamp(v.CreateTime)
	}
	return &Article.TimeLineVoList{
		TimeLineVoList: articleTimeLineVo,
	}, nil
}
